| Conditions | 1 |
| Paths | 1 |
| Total Lines | 52 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | /** |
||
| 16 | describe('Analysis', function() { |
||
| 17 | |||
| 18 | describe('getUserAnalysis()', function() { |
||
| 19 | it('Initiate by welcoming user by asking name', function() { |
||
| 20 | var bot = new Bot(topicList, topics); |
||
| 21 | bot.transformAndReply("aQ11zyTr4u7I", null, null, function(err, response){ |
||
| 22 | expect(response).to.match(/^What is your name?/); |
||
| 23 | }); |
||
| 24 | }); |
||
| 25 | |||
| 26 | it('Should remember your name.', function() { |
||
| 27 | var bot = new Bot(topicList, topics); |
||
| 28 | bot.transformAndReply("aQ11zyTr4u7I", null, "Hardik Shah", function(err, response){ |
||
| 29 | expect(response).to.match(/^Hello Hardik Shah, I am HSBOT and I will help you./); |
||
| 30 | }); |
||
| 31 | }); |
||
| 32 | |||
| 33 | it('Should Analyze data.', function() { |
||
| 34 | var bot = new Bot(topicList, topics); |
||
| 35 | var userAnalysis = bot.getUserAnalysis("aQ11zyTr4u7I"); |
||
| 36 | expect(userAnalysis).to.have.all.keys('timeSpent', 'frequentBotText', 'frequentUserText'); |
||
| 37 | }); |
||
| 38 | }); |
||
| 39 | |||
| 40 | describe('getChatHistory()', function() { |
||
| 41 | it('Should return user details.', function() { |
||
| 42 | var bot = new Bot(topicList, topics); |
||
| 43 | var user = bot.getChatHistory("aQ11zyTr4u7I"); |
||
| 44 | expect(user).to.have.all.keys('userId', 'userName', 'activities', 'loggedIn'); |
||
| 45 | expect(user.activities).to.have.length(2); |
||
| 46 | }); |
||
| 47 | }); |
||
| 48 | |||
| 49 | describe('getAllUserChatHistory()', function() { |
||
| 50 | it('Should return all user details.', function() { |
||
| 51 | var bot = new Bot(topicList, topics); |
||
| 52 | var user = bot.getAllUserChatHistory(); |
||
| 53 | expect(user).to.have.length(1); |
||
| 54 | expect(user[0]).to.have.all.keys('userId', 'userName', 'activities', 'loggedIn'); |
||
| 55 | }); |
||
| 56 | }); |
||
| 57 | |||
| 58 | describe('analysis._analyzed()', function() { |
||
| 59 | it('Should return all user details.', function() { |
||
| 60 | var userData = dummyData.userData; |
||
| 61 | var analysis = new Analysis(); |
||
| 62 | var userAnalysis = analysis._analyzed(userData); |
||
| 63 | expect(userAnalysis).to.have.all.keys('timeSpent', 'frequentBotText', 'frequentUserText'); |
||
| 64 | }); |
||
| 65 | }); |
||
| 66 | |||
| 67 | }); |